package cn.wzptsoft.tinymallbe.controller;

import cn.wzptsoft.common.utils.Result;
import cn.wzptsoft.tinymallbe.entity.Category;
import cn.wzptsoft.tinymallbe.service.CategoryService;
import cn.wzptsoft.tinymallbe.vo.CategoryVo;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("category")
public class CategoryController {
    final
    CategoryService categoryService;

    public CategoryController(CategoryService categoryService) {
        this.categoryService = categoryService;
    }

    /**
     * 查询所有商品分类
     */
    @GetMapping("/all")
    public Result<CategoryVo> getAll() {
        CategoryVo all = categoryService.getAll();
        return Result.ok(all);
    }

    /**
     * 查找根分类 用于宫格展示
     */
    @GetMapping("/grid")
    public Result<List<Category>> getGridCategoryList() {
        List<Category> rootCategory = categoryService.getRootCategory();
        return Result.ok(rootCategory);
    }

}
